<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/tags.jsp"%>
<aos:html>
<aos:head title="订单管理列表">
	<aos:include lib="ext" />
	<aos:base href="console/agentorder" />
</aos:head>
<aos:body>
</aos:body>
<aos:onready>
	<aos:viewport layout="border">
		<aos:formpanel id="qform" labelWidth="70" region="north"
			header="false" padding="5 0 0 0" border="false">
			<aos:textfield fieldLabel="客户公司" name="customer_name" />
			<aos:button width="80" text="查 询" margin="0 0 0 15px"
				icon="search.png" onclick="query"></aos:button>
			<aos:button width="80" text="重 置" margin="0 0 0 15px"
				icon="refresh1.png" onclick="AOS.reset(qform)"></aos:button>
		</aos:formpanel>
		<aos:gridpanel id="grid" url="list" onrender="query"
			 region="center">
			<aos:docked>
				<aos:dockeditem onclick="show_add" text="新增提单" icon="add.png" />
				<aos:dockeditem onclick="show_add_request" text="上传申请函"
					icon="add.png" />
				<aos:dockeditem onclick="show_add_contract" text="上传合同"
					icon="add.png" />
			</aos:docked>
			<aos:selmodel type="checkbox" mode="multi" />
			<aos:column type="rowno" header="序号" width="40" />
			<aos:column header="id" dataIndex="id" width="40" />

			<aos:column header="客户单号" dataIndex="order_num" width="60" />
			<aos:column header="客户/公司名称" dataIndex="customer_name" width="60" />
			<aos:column header="联系人" dataIndex="customer_person" width="60" />

			<aos:column header="代理商ID" dataIndex="agent_id" hidden="true" width="60" />
			<aos:column header="代理商公司" dataIndex="agent_name" width="60" />
			<aos:column header="申请函" dataIndex="customer_request" width="60"
				rendererFn="customer_request_ren" />
			<aos:column header="合同" dataIndex="customer_contract" width="60"
				rendererFn="customer_contract_ren" />
			<aos:column header="备注" dataIndex="remark" width="60" />
			<aos:column header="讲师ID" dataIndex="teacher_id" width="60" />
			<aos:column header="讲师" dataIndex="teacher_name" width="60" />
			<aos:column header="状态" dataIndex="state" width="60"
				rendererFn="state_ren" />
			<aos:column header="签单时间" dataIndex="order_time" width="60" />
			<aos:column header="提单时间" dataIndex="create_time" width="60" />

		</aos:gridpanel>

		<aos:window id="add_w" title="新增提单" maxHeight="-10" autoScroll="true">

			<aos:formpanel id="add_f" width="420" layout="anchor" labelWidth="80">
				<aos:combobox name="teacher_id" fieldLabel="讲师" url="../findTeacher"
					emptyText="－－请选择－－" allowBlank="false" />
				<aos:textfield fieldLabel="客户/公司名称" name="customer_name" />
				<aos:textfield fieldLabel="客户/公司地址" name="customer_address" />
				<aos:textfield fieldLabel="客户/公司联系人" name="customer_person" />
				<aos:textfield fieldLabel="客户/公司联系方式" name="customer_mobile" />
				<aos:textareafield name="remark" fieldLabel="备注" />
				<aos:datetimefield name="order_time" fieldLabel="签单时间"
					allowBlank="false" />
			</aos:formpanel>


			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="add" text="保存" icon="ok.png" />
				<aos:dockeditem onclick="#add_w.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>

		<aos:window id="add_request_w" title="上传申请函" maxHeight="-10"
			autoScroll="true">

			<aos:formpanel id="add_request_f" width="420" layout="anchor"
				labelWidth="80">
				<aos:textfield name="id" fieldLabel="ID" allowBlank="false"
					readOnly="true" />
				<aos:filefield name="customer_request" fieldLabel="申请函"
					buttonText="浏览" emptyText="请选择文件..." />
			</aos:formpanel>

			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="_f_upload_submit" text="保存" icon="ok.png" />
				<aos:dockeditem onclick="#add_request_w.hide();" text="关闭"
					icon="close.png" />
			</aos:docked>
		</aos:window>

		<aos:window id="add_contract_w" title="上传合同" maxHeight="-10"
			autoScroll="true">

			<aos:formpanel id="add_contract_f" width="420" layout="anchor"
				labelWidth="80">
				<aos:textfield name="id" fieldLabel="ID" allowBlank="false"
					readOnly="true" />
				<aos:filefield name="customer_contract" fieldLabel="合同"
					buttonText="浏览" emptyText="请选择文件..." />
			</aos:formpanel>

			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="_f_contract_upload_submit" text="保存"
					icon="ok.png" />
				<aos:dockeditem onclick="#add_contract_w.hide();" text="关闭"
					icon="close.png" />
			</aos:docked>
		</aos:window>

		<aos:window id="update_w" title="修改提单" maxHeight="-10"
			autoScroll="true">
			<aos:formpanel id="update_f" width="420" layout="anchor"
				labelWidth="80">

			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="update" text="修改" icon="ok.png" />
				<aos:dockeditem onclick="#update_w.hide();" text="关闭"
					icon="close.png" />
			</aos:docked>
		</aos:window>
	</aos:viewport>

	<script type="text/javascript">
	
    function _f_contract_upload_submit() {
        var form = add_contract_f.getForm();
        if (!form.isValid()) {
            return;
        }     
      
        AOS.wait();
        form.submit({
            timeout: 60000, // 60s
            url: 'uploadcontract',
            success: function (form, action) {
                if (action.result.code !== -1) {
                    //成功
                     add_contract_w.hide();
                }
                AOS.hide();
                grid_store.reload();
                grid.getSelectionModel().clearSelections();
                AOS.tip(action.result.value);
            }
        });
    }
	
    function _f_upload_submit() {
        var form = add_request_f.getForm();
        if (!form.isValid()) {
            return;
        }     
      
        AOS.wait();
        form.submit({
            timeout: 60000, // 60s
            url: 'uploadrequest',
            success: function (form, action) {
                if (action.result.code !== -1) {
                    //成功
                     add_request_w.hide();
                }
                AOS.hide();
                grid_store.reload();
                grid.getSelectionModel().clearSelections();
                AOS.tip(action.result.value);
            }
        });
    }
    
    function customer_request_ren(v){	 	 
	 	if(v != null)
			return '<a target="_blank" href=../../attaches/'+v+'>查看</a>';		
		else
			return v;
	}
    
    function customer_contract_ren(v){   
	 	if(v != null)
			return '<a target="_blank" href=../../attaches/'+v+'>查看</a>';		
		else
			return v;
	}
    
    function state_ren(v){
		if(v == 1){
			return '新增'
		}else if(v == 2){
			return '回访'
		}else{
			return v
		}
	}

   	 
    function query(){
        grid_store.getProxy().extraParams = qform.getValues();
        grid_store.getProxy().getMethod = function(){ return 'POST'; }
        grid_store.load();
     }

	function show_add(){
		AOS.reset(add_f);
        add_w.show();
	}
	
	function show_add_request(){	
        AOS.reset(add_request_f);
        grid_store.reload();           
        var record = AOS.selectone(grid);
        grid.getSelectionModel().clearSelections();
        if(record){
        	add_request_w.show();
        	add_request_f.loadRecord(record);
        }
	}
	
	function show_add_contract(){	
        AOS.reset(add_contract_f);
        grid_store.reload();           
        var record = AOS.selectone(grid);
        grid.getSelectionModel().clearSelections();
        if(record){
        	add_contract_w.show();
        	add_contract_f.loadRecord(record);
        }
	}
	
	function add(){
		AOS.ajax({
            forms : add_f,
            url : 'add',
            ok : function(data) {
                	if(data.success){
                		 add_w.hide();
                     grid_store.reload();
                	}
                AOS.tip(data.appmsg);
            }
        }); 
	}
    function show_update(){
        AOS.reset(update_f);
        grid_store.reload();           
        var record = AOS.selectone(grid);
        grid.getSelectionModel().clearSelections();
        if(record){
            update_w.show();
            update_f.loadRecord(record);
        }
    }        
    
    function update(){
           AOS.ajax({
            forms : update_f,
            url : 'update',
            ok : function(data) {
                	if(data.success){
                		update_w.hide();
                    grid_store.reload();
                    grid.getSelectionModel().clearSelections()
                	}
                	AOS.tip(data.appmsg);
            }
        }); 
    }
    </script>
</aos:onready>
</aos:html>